package abio.XasML.rpc
{
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	
	public class command
	{
		private var delayedCall:Function=null;
		private var responder:IResponder=null;

		public function command(delayedCall:Object, resultHandler:Function, faultHandler:Function=null)
		{
			if(delayedCall is Function){
				this.delayedCall=delayedCall as Function;
		//	}esle if(delayedCall is AbstractInvoker){				对于纯as项目节省了约100kb编译后大小
			}else if(delayedCall.hasOwnProperty('send')){
				this.delayedCall=delayedCall.send;
			}
			this.responder=new Responder(resultHandler, faultHandler);
		}

		public function execute(...args):AsyncToken{
			var result:AsyncToken=this.delayedCall.apply(null, args);
			result.addResponder(this.responder);
			return result;
		}
	}
}